package com.gzx.plugin.tjzy.modular.liaison.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.liaison.entity.bo.GzxDebtorLiaisonAddOrEditBo;
import com.gzx.plugin.tjzy.modular.liaison.entity.bo.GzxDebtorLiaisonQueryBo;
import com.gzx.plugin.tjzy.modular.liaison.entity.vo.GzxDebtorLiaisonVo;
import com.gzx.plugin.tjzy.modular.liaison.service.GzxDebtorLiaisonService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;

import java.io.IOException;
import java.util.Map;

/**
 * @author zjt
 * @description
 * @date 2024/12/4 15:45
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/debtor/liaison")
public class GzxDebtorLiaisonController {


    private final GzxDebtorLiaisonService debtorLiaisonService;

    @PostMapping("/pageList")
    public CommonResult<Page<GzxDebtorLiaisonVo>> pageList(@RequestBody GzxDebtorLiaisonQueryBo debtorLiaisonQueryBo) throws IllegalAccessException {
        return CommonResult.data(debtorLiaisonService.pageList(debtorLiaisonQueryBo));
    }

    @PostMapping("/importLiaison")
    @CommonLog("联系人导入")
    public CommonResult<Void> importExcel(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        debtorLiaisonService.importExcel(multipartFile);
        return CommonResult.ok();
    }

    @PostMapping("/addOrEdit")
    @CommonLog("联系人新增或者修改")
    public CommonResult<Void> addOrEdit(@RequestBody GzxDebtorLiaisonAddOrEditBo debtorLiaisonAddOrEditBo) {
        debtorLiaisonService.addOrEdit(debtorLiaisonAddOrEditBo);
        return CommonResult.ok();
    }

    @GetMapping("/getLiaisonPhoneById/{id}")
    public CommonResult<Map> getLiaisonPhoneById(@PathVariable Long id, @RequestParam(required = false) boolean isCatch) {
        return CommonResult.data(debtorLiaisonService.getLiaisonPhoneById(id, isCatch));
    }

    @GetMapping("/deleteById/{id}")
    @CommonLog("联系人删除")
    public CommonResult<String> deleteById(@PathVariable Long id) {
        debtorLiaisonService.deleteById(id);
        return CommonResult.ok();
    }

    @GetMapping("/addPhoneTodayCallCount/{liaisonPhone}")
    public CommonResult<String> addPhoneTodayCallCount(@PathVariable String liaisonPhone) {
        debtorLiaisonService.addPhoneTodayCallCount(liaisonPhone);
        return CommonResult.ok();
    }
}
